package log.aop;

import log.constant.LogConstants;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


import lombok.extern.slf4j.Slf4j;

/**
 * @author
 * @Desc
 * @date 2021/6/30 9:27
 */
@Slf4j
@Aspect
@Order(2)
@Component
public class ConsoleControllerAspect extends BaseAspect {

    /***/
    @Pointcut("@within(org.springframework.web.bind.annotation.RestController)"
        + "&&( @annotation(org.springframework.web.bind.annotation.PostMapping)"
        + "|| @annotation(org.springframework.web.bind.annotation.GetMapping))")
    public void pointCut() {}

    /***/
    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        String param = super.getRequestParams(point);
        super.outputConsoleLogs(point, LogConstants.STOREY_CONTROLLER, LogConstants.IN, param);
        Object result = point.proceed();
        super.outputConsoleLogs(point, LogConstants.STOREY_CONTROLLER, LogConstants.OUT, null);
        return result;
    }

}
